/**
 * JS实现继承的几种方式
 * 
 * https://juejin.cn/post/7038757474442149895
 * 
 * 1、原型链继承
 * 2、构造继承
 * 3、实例继承
 * 4、拷贝继承
 * 5、组合继承
 * 6、寄生组合继承
*/
// 1、原型链继承
function Parent() {
  this.name = 'parent';
  this.play = [1, 2, 3];
}
function Child() {
  this.type = 'child';
}
Child.prototype = new Parent();
var child1 = new Child();
var child2 = new Child();
console.log(child1.play); // [1, 2, 3]
console.log(child2.play); // [1, 2, 3]
child1.play.push(4);
console.log(child1.play); // [1, 2, 3, 4]
console.log(child2.play); // [1, 2, 3, 4]

// 2、构造继承
function Parent(name) {
  this.name = name;
  this.play = [1, 2, 3];
}
function Child(name) {
  Parent.call(this, name);
  this.type = 'child';
}
var child1 = new Child('child1');
var child2 = new Child('child2');
console.log(child1.name); // child1
console.log(child2.name); // child2
child1.play.push(4);
console.log(child1.play); // [1, 2, 3, 4]
console.log(child2.play); // [1, 2, 3]

// 3、实例继承
function Parent() {
  this.name = 'parent';
  this.play = [1, 2, 3];
}
function Child() {
  var instance = new Parent();
  instance.type = 'child';
  return instance;
}
var child1 = new Child();
var child2 = new Child();
console.log(child1.play); // [1, 2, 3]
console.log(child2.play); // [1, 2, 3]
child1.play.push(4);
console.log(child1.play); // [1, 2, 3, 4]
console.log(child2.play); // [1, 2, 3]

// 4、拷贝继承
function Parent() {
  this.name = 'parent';
  this.play = [1, 2, 3];
}
function Child() {
  Parent.call(this);
  this.type = 'child';
}
var child1 = new Child();
var child2 = new Child();
